<?php
/*! \brief
 * This is extension class SqlGen for Mysql
 * \author William Su
 */
require_once dirname(__FILE__) . '/SqlGen.abstract.php';
class WFSqlGenMysql extends ASqlGen
{
    public function __construct($objFramework){
        $strPrefixSymbolTable = '`';
        $strSuffixSymbolTable = '`';
        parent::__construct($objFramework, $strPrefixSymbolTable, $strSuffixSymbolTable);
    }
    public function getCreateDatabase(){
        $ret = 'CREATE DATABASE IF NOT EXISTS ' . $this->objFramework->getConfigFactory()->getConfig()->getDbConfigDbname() . ' DEFAULT CHARACTER SET = utf8';
        return $ret;
    }
    public function getCreateTableWidget(){
        $ret = 'CREATE TABLE IF NOT EXISTS `WIDGET`
(
    `widget_id` INTEGER(11)  NOT NULL AUTO_INCREMENT,
    `widget_name` VARCHAR(255),
    `modname` VARCHAR(50),
    `widget_version` VARCHAR(50),
    `widget_version_float` FLOAT default 0,
    `widget_type` INTEGER(4) default 1,
    `widget_min_wf_version` VARCHAR(255),
    `widget_min_wf_version_float` FLOAT default 0,
    `widget_status` INTEGER(4) default 0,
    `widget_status_update` INTEGER(4) default 0,
    `user_generated` INTEGER(4) default 0,
    `icon` VARCHAR(255),
    `icon_preview` VARCHAR(255),
    `widget_key` VARCHAR(50),
    `param` TEXT,
    `createtime` INTEGER(11),
    `edittime` INTEGER(11),
    PRIMARY KEY (`widget_id`)
) ENGINE=InnoDB CHARACTER SET \'utf8\'';
        return $ret;
    }
    public function getCreateTableWidgetCategory(){
        $ret = 'CREATE TABLE IF NOT EXISTS `WIDGET_CATEGORY`
(
    `category_id` INTEGER(11)  NOT NULL AUTO_INCREMENT,
    `category_name` VARCHAR(255),
    `createtime` INTEGER(11),
    `edittime` INTEGER(11),
    PRIMARY KEY (`category_id`)
) ENGINE=InnoDB CHARACTER SET \'utf8\'';
        return $ret;
    }
    public function getCreateTableWidgetCategoryMapping(){
        $ret = 'CREATE TABLE IF NOT EXISTS `WIDGET_CATEGORY_MAPPING`
(
    `mapping_id` INTEGER(11)  NOT NULL AUTO_INCREMENT,
    `widget_id` INTEGER(11)  NOT NULL,
    `category_id` INTEGER(11)  NOT NULL,
    `min_support_version` VARCHAR(255),
    `min_support_version_float` FLOAT default 0,
    `createtime` INTEGER(11),
    `edittime` INTEGER(11),
    PRIMARY KEY (`mapping_id`),
    INDEX (`widget_id`),
    INDEX (`category_id`)
) ENGINE=InnoDB CHARACTER SET \'utf8\'';
        return $ret;
    }
    public function getCreateTableWpUpdateFilter(){
        $ret = 'CREATE TABLE IF NOT EXISTS `WP_UPDATE_FILTER`
(
    `filter_id` INTEGER(11)  NOT NULL AUTO_INCREMENT,
    `filter_key` VARCHAR(255),
    `file_interface` VARCHAR(255),
    `filter_target` VARCHAR(255),
    `filter_condition` VARCHAR(255),
    `createtime` INTEGER(11),
    `edittime` INTEGER(11),
    PRIMARY KEY (`filter_id`)
) ENGINE=InnoDB CHARACTER SET \'utf8\'';
        return $ret;
    }
    public function getCreateTableWpUpdateLog(){
        $ret = '
CREATE TABLE IF NOT EXISTS `WP_UPDATE_LOG`
(
    `log_id` INTEGER(11)  NOT NULL AUTO_INCREMENT,
    `status` INTEGER(4) default 0,
    `fail_point` INTEGER(6) default 0,
    `before_update_widgets` TEXT,
    `before_update_widget_components` TEXT,
    `createtime` INTEGER(11),
    `edittime` INTEGER(11),
    PRIMARY KEY (`log_id`)
) ENGINE=InnoDB CHARACTER SET \'utf8\'';
        return $ret;
    }
    public function getCreateTableProxylist(){
        $ret = 'CREATE TABLE IF NOT EXISTS `proxylist`
(
    `id` INTEGER(11)  NOT NULL AUTO_INCREMENT,
    `owner` INTEGER(11),
    `deleted` INTEGER(11),
    `lastcheck` INTEGER(11),
    `name` TEXT,
    `hostinfo` TEXT,
    `guid` VARCHAR(50),
    PRIMARY KEY (`id`)
) ENGINE=InnoDB CHARACTER SET \'utf8\'';
        return $ret;
    }
    public function getCreateTableServerlist(){
        $ret = 'CREATE TABLE IF NOT EXISTS `serverlist`
(
    `id` INTEGER(11)  NOT NULL AUTO_INCREMENT,
    `owner` INTEGER(11),
    `deleted` INTEGER(11),
    `lastcheck` INTEGER(11),
    `name` TEXT,
    `hostinfo` TEXT,
    PRIMARY KEY (`id`)
) ENGINE=InnoDB CHARACTER SET \'utf8\'';
        return $ret;
    }
    public function getCreateTableServerlisttype(){
        $ret = 'CREATE TABLE IF NOT EXISTS `serverlisttype`
(
    `id` INTEGER(11)  NOT NULL AUTO_INCREMENT,
    `type` VARCHAR(50) ,
    `passwordonly` INTEGER(11),
    `customFields` TEXT,
    PRIMARY KEY (`id`),
    UNIQUE KEY `type` (`type`)
) ENGINE=InnoDB CHARACTER SET \'utf8\'';
        return $ret;
    }
    public function getCreateTableUserdata(){
        $ret = 'CREATE TABLE IF NOT EXISTS `userdata`
(
    `id` INTEGER(11)  NOT NULL AUTO_INCREMENT,
    `uid` INTEGER(11),
    `wid` INTEGER(11),
    `modname` VARCHAR(50),
    `data` TEXT,
    `pid` INTEGER(11),
    `widget_key` VARCHAR(50),
    `param` TEXT,    
    PRIMARY KEY (`id`),
    INDEX (`uid`),
    INDEX (`wid`),
    INDEX (`pid`)
) ENGINE=InnoDB CHARACTER SET \'utf8\'';
        return $ret;
    }
    public function getCreateTableUsers(){
        $ret = 'CREATE TABLE IF NOT EXISTS `users`
(
    `id` INTEGER(11)  NOT NULL AUTO_INCREMENT,
    `email` VARCHAR(100),
    `pass` VARCHAR(50),
    `data` TEXT,
    `cdata` TEXT,
    `udata` TEXT,
    `pdata` TEXT,
    `lang` VARCHAR(10),
    `theme` VARCHAR(20),
    PRIMARY KEY (`id`)
) ENGINE=InnoDB CHARACTER SET \'utf8\'';
        return $ret;
    }
    public function getCreateTableContainer(){
        $ret = 'CREATE TABLE IF NOT EXISTS `CONTAINER`
(
    `container_id` INTEGER(11)  NOT NULL AUTO_INCREMENT,
    `container_name` VARCHAR(255),
    `container_param` TEXT,
    `container_type_name` VARCHAR(255),
    PRIMARY KEY (`container_id`)
) ENGINE=InnoDB CHARACTER SET \'utf8\'';
        return $ret;
    }
    public function getCreateTableWidgetComponent(){
        $ret = 'CREATE TABLE IF NOT EXISTS `WIDGET_COMPONENT`
(
    `wcomponent_id` INTEGER(11)  NOT NULL AUTO_INCREMENT,
    `wcomponent_name` VARCHAR(255),
    `wcomponent_version` VARCHAR(50),
    `wcomponent_version_float` FLOAT default 0,
    `wcomponent_min_support_version` VARCHAR(50),
    `wcomponent_min_support_version_float` FLOAT default 0,
    `wcomponent_status` INTEGER(4) default 0,
    `wcomponent_status_update` INTEGER(4) default 0,
    `wcomponent_param` TEXT,
    `createtime` INTEGER(11),
    `edittime` INTEGER(11),
    PRIMARY KEY (`wcomponent_id`)
) ENGINE=InnoDB CHARACTER SET \'utf8\'';
        return $ret;
    }
    public function getCreateTableWidgetComponentCategory(){
        $ret = 'CREATE TABLE IF NOT EXISTS `WIDGET_COMPONENT_CATEGORY`
(
    `category_id` INTEGER(11)  NOT NULL AUTO_INCREMENT,
    `category_name` VARCHAR(255),
    `category_product_id` FLOAT,
    `category_proxy` VARCHAR(50),
    `createtime` INTEGER(11),
    `edittime` INTEGER(11),
    PRIMARY KEY (`category_id`)
) ENGINE=InnoDB CHARACTER SET \'utf8\'';
        return $ret;
    }
    public function getCreateTableWidgetComponentCategoryMapping(){
        $ret = 'CREATE TABLE IF NOT EXISTS `WIDGET_COMPONENT_CATEGORY_MAPPING`
(
    `mapping_id` INTEGER(11)  NOT NULL AUTO_INCREMENT,
    `wcomponent_id` INTEGER(11)  NOT NULL,
    `category_id` INTEGER(11)  NOT NULL,
    `min_support_version` VARCHAR(50),
    `min_support_version_float` FLOAT default 0,
    `createtime` INTEGER(11),
    `edittime` INTEGER(11),
    PRIMARY KEY (`mapping_id`),
    INDEX (`wcomponent_id`),
    INDEX (`category_id`)
) ENGINE=InnoDB CHARACTER SET \'utf8\'';
        return $ret;
    }
    public function getDropTableWidget(){
        $ret = 'DROP TABLE IF EXISTS ' . $this->strPrefixSymbolTable . 'WIDGET' . $this->strSuffixSymbolTable;
        return $ret;
    }
    public function getDropTableWidgetCategory(){
        $ret = 'DROP TABLE IF EXISTS ' . $this->strPrefixSymbolTable . 'WIDGET_CATEGORY' . $this->strSuffixSymbolTable;
        return $ret;
    }
    public function getDropTableWidgetCategoryMapping(){
        $ret = 'DROP TABLE IF EXISTS ' . $this->strPrefixSymbolTable . 'WIDGET_CATEGORY_MAPPING' . $this->strSuffixSymbolTable;
        return $ret;
    }
    public function getDropTableWpUpdateFilter(){
        $ret = 'DROP TABLE IF EXISTS ' . $this->strPrefixSymbolTable . 'WP_UPDATE_FILTER' . $this->strSuffixSymbolTable;
        return $ret;
    }
    public function getDropTableWpUpdateLog(){
        $ret = 'DROP TABLE IF EXISTS ' . $this->strPrefixSymbolTable . 'WP_UPDATE_LOG' . $this->strSuffixSymbolTable;
        return $ret;
    }
    public function getDropTableProxylist(){
        $ret = 'DROP TABLE IF EXISTS ' . $this->strPrefixSymbolTable . 'proxylist' . $this->strSuffixSymbolTable;
        return $ret;
    }
    public function getDropTableServerlist(){
        $ret = 'DROP TABLE IF EXISTS ' . $this->strPrefixSymbolTable . 'serverlist' . $this->strSuffixSymbolTable;
        return $ret;
    }
    public function getDropTableServerlisttype(){
        $ret = 'DROP TABLE IF EXISTS ' . $this->strPrefixSymbolTable . 'serverlisttype' . $this->strSuffixSymbolTable;
        return $ret;
    }
    public function getDropTableUserdata(){
        $ret = 'DROP TABLE IF EXISTS ' . $this->strPrefixSymbolTable . 'userdata' . $this->strSuffixSymbolTable;
        return $ret;
    }
    public function getDropTableUsers(){
        $ret = 'DROP TABLE IF EXISTS ' . $this->strPrefixSymbolTable . 'users' . $this->strSuffixSymbolTable;
        return $ret;
    }
    public function getDropTableContainer(){
        $ret = 'DROP TABLE IF EXISTS ' . $this->strPrefixSymbolTable . 'CONTAINER' . $this->strSuffixSymbolTable;
        return $ret;
    }
    public function getDropTableWidgetComponent(){
        $ret = 'DROP TABLE IF EXISTS ' . $this->strPrefixSymbolTable . 'WIDGET_COMPONENT' . $this->strSuffixSymbolTable;
        return $ret;
    }
    public function getDropTableWidgetComponentCategory(){
        $ret = 'DROP TABLE IF EXISTS ' . $this->strPrefixSymbolTable . 'WIDGET_COMPONENT_CATEGORY' . $this->strSuffixSymbolTable;
        return $ret;
    }
    public function getDropTableWidgetComponentCategoryMapping(){
        $ret = 'DROP TABLE IF EXISTS ' . $this->strPrefixSymbolTable . 'WIDGET_COMPONENT_CATEGORY_MAPPING' . $this->strSuffixSymbolTable;
        return $ret;
    }
    public function getTruncateTableWidget(){
        $ret = 'TRUNCATE TABLE ' . $this->strPrefixSymbolTable . 'WIDGET' . $this->strSuffixSymbolTable;
        return $ret;
    }
    public function getTruncateTableWidgetCategory(){
        $ret = 'TRUNCATE TABLE ' . $this->strPrefixSymbolTable . 'WIDGET_CATEGORY' . $this->strSuffixSymbolTable;
        return $ret;
    }
    public function getTruncateTableWidgetCategoryMapping(){
        $ret = 'TRUNCATE TABLE ' . $this->strPrefixSymbolTable . 'WIDGET_CATEGORY_MAPPING' . $this->strSuffixSymbolTable;
        return $ret;
    }
    public function getTruncateTableWpUpdateFilter(){
        $ret = 'TRUNCATE TABLE ' . $this->strPrefixSymbolTable . 'WP_UPDATE_FILTER' . $this->strSuffixSymbolTable;
        return $ret;
    }
    public function getTruncateTableWpUpdateLog(){
        $ret = 'TRUNCATE TABLE ' . $this->strPrefixSymbolTable . 'WP_UPDATE_LOG' . $this->strSuffixSymbolTable;
        return $ret;
    }
    public function getTruncateTableProxylist(){
        $ret = 'TRUNCATE TABLE ' . $this->strPrefixSymbolTable . 'proxylist' . $this->strSuffixSymbolTable;
        return $ret;
    }
    public function getTruncateTableServerlist(){
        $ret = 'TRUNCATE TABLE ' . $this->strPrefixSymbolTable . 'serverlist' . $this->strSuffixSymbolTable;
        return $ret;
    }
    public function getTruncateTableServerlisttype(){
        $ret = 'TRUNCATE TABLE ' . $this->strPrefixSymbolTable . 'serverlisttype' . $this->strSuffixSymbolTable;
        return $ret;
    }
    public function getTruncateTableUserdata(){
        $ret = 'TRUNCATE TABLE ' . $this->strPrefixSymbolTable . 'userdata' . $this->strSuffixSymbolTable;
        return $ret;
    }
    public function getTruncateTableUsers(){
        $ret = 'TRUNCATE TABLE ' . $this->strPrefixSymbolTable . 'users' . $this->strSuffixSymbolTable;
        return $ret;
    }
    public function getTruncateTableContainer(){
        $ret = 'TRUNCATE TABLE ' . $this->strPrefixSymbolTable . 'CONTAINER' . $this->strSuffixSymbolTable;
        return $ret;
    }
    public function getTruncateTableWidgetComponent(){
        $ret = 'TRUNCATE TABLE ' . $this->strPrefixSymbolTable . 'WIDGET_COMPONENT' . $this->strSuffixSymbolTable;
        return $ret;
    }
    public function getTruncateTableWidgetComponentCategory(){
        $ret = 'TRUNCATE TABLE ' . $this->strPrefixSymbolTable . 'WIDGET_COMPONENT_CATEGORY' . $this->strSuffixSymbolTable;
        return $ret;
    }
    public function getTruncateTableWidgetComponentCategoryMapping(){
        $ret = 'TRUNCATE TABLE ' . $this->strPrefixSymbolTable . 'WIDGET_COMPONENT_CATEGORY_MAPPING' . $this->strSuffixSymbolTable;
        return $ret;
    }
}
